namespace HCC {
﻿#include <mysql.h>

typedef struct
{
	char  * username;
	char  * password;
	char  * host;
}
login_t;

void  work_with_db(MYSQL*);

MYSQL* connect_to_db(login_t* login)
{
	MYSQL* mysql = NULL;

	mysql = mysql_init(mysql);

	if  (!mysql)
	{
		return  mysql;
	}

	if  (!mysql_real_connect(mysql,
		login->host,
		login->username,
		login->password,
		NULL,
		0,
		NULL,
		CLIENT_FOUND_ROWS))
	{
		return  NULL;
	}
	  else
	  {
	  return  mysql;
	  }
}

int  main(int  argc, char  * argv[])
{
	login_t login = { "username" ,  "password" ,  "localhost" };

	MYSQL* mysql = connect_to_db(&login);

	if  (!mysql)
	{
		return   - 1;
	}

	work_with_db(mysql);
	mysql_close(mysql);

	return  0;
}








#include <string>

bool connectToServer(const std::string& userAndPassword)
{
	if (userAndPassword == "alice:s3cr3t")
		return true;
	return false;
}









#include <mysql.h>

typedef struct 
{
	char* username;
	char* password;
	char* host;
}
login_t;

login_t read_and_decrypt_auth_info();
void work_with_db(MYSQL*);

MYSQL* connect_to_db(login_t* login)
{
	MYSQL* mysql = NULL;

	mysql = mysql_init(mysql);

	if (!mysql)
	{
		return mysql;
	}

	if (!mysql_real_connect(mysql,
		login->host,
		login->username,
		login->password,
		NULL,
		0,
		NULL,
		CLIENT_FOUND_ROWS))
	{
		return NULL;
	}
	else 
	{
		return mysql;
	}
}

int main(int argc, char* argv[])
{
	login_t login = read_and_decrypt_auth_info();

	MYSQL* mysql = connect_to_db(&login);

	if (!mysql)
	{
		return -1;
	}

	work_with_db(mysql);
	mysql_close(mysql);

	return 0;
}





#include <string>

namespace database 
{
	bool checkServerCredentials(const std::string& userAndPassword);
}

bool connectToServer(const std::string& userAndPassword)
{
	return database::checkServerCredentials(userAndPassword);
}
}}